<!DOCTYPE html>
<html>

<head>
  <title>Upload Files using XMLHttpRequest - Minimal</title>

  <script type="text/javascript">

    function uploadFile() {
      var fd = new FormData();
      var fileNum = document.getElementById('fileToUpload').files.length;
      for(var i=0; i<fileNum; ++i){
        fd.append("fileToUpload",document.getElementById('fileToUpload').files[i])
      }

      var xhr = new XMLHttpRequest();
      xhr.upload.addEventListener("progress", uploadProgress, false);
      xhr.addEventListener("load", uploadComplete, false);
      xhr.addEventListener("error", uploadFailed, false);
      xhr.addEventListener("abort", uploadCanceled, false);
      xhr.open("POST", "up");
      xhr.send(fd);
    }

    function uploadProgress(evt) {
      if (evt.lengthComputable) {
        var percentComplete = Math.round(evt.loaded * 100 / evt.total);
        document.getElementById('progressNumber').innerHTML = percentComplete.toString() + '%';
      }
      else {
        document.getElementById('progressNumber').innerHTML = 'unable to compute';
      }
    }

    function uploadComplete(evt) {
      /* This event is raised when the server send back a response */
      document.getElementById('result').innerHTML=evt.target.responseText
      var content = evt.target.responseText;
      var index = -1;
      var link ="";
      var number = 0;
      while((index = content.indexOf("MD5"))>0){
        number ++;
        var sublink = window.location.href+"simple_down?md5="+content.substring(index+6,index+32+6)
        link += `<a href="`+sublink+`"  target="_blank">`+"地址"+number+`<\a>  `
        content = content.substring(index+32+6)
      }
      document.getElementById('link').innerHTML = link;
    }

    function uploadFailed(evt) {
      alert("There was an error attempting to upload the file.");
    }

    function uploadCanceled(evt) {
      alert("The upload has been canceled by the user or the browser dropped the connection.");
    }
  </script>
</head>

<body>
  <div class="row">
    <label for="fileToUpload">Select a File to Upload</label>
    <input type="file" name="fileToUpload" id="fileToUpload" multiple="multiple"  />
  </div>

  <div class="row">
    <input type="button" onclick="uploadFile()" value="Upload" />
  </div>
  <div id="progressNumber"></div>
  服务端返回值：
  <div id="result"></div>
  根据返回值生成的下载地址：
  <div id="link"></div>
</body>

</html>